<!DOCTYPE html>
<html>
<head>
    <title>注册</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <!-- Custom Theme files -->
    <link href="css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <link href="css/snow.css" rel="stylesheet" type="text/css"/>
    <link href="css/style.css" rel="stylesheet" type="text/css"/>
    <!-- //Custom Theme files -->
    <!-- jquery -->
    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <script type="text/javascript" src="/bootstrap/js/bootstrap.min.js"></script>
    <!-- jquery-validator -->
    <script type="text/javascript" src="/jquery-validation/jquery.validate.min.js"></script>
    <script type="text/javascript" src="/jquery-validation/localization/messages_zh.min.js"></script>
    <!-- layer -->
    <script type="text/javascript" src="/layer/layer.js"></script>
    <!-- md5.js -->
    <script type="text/javascript" src="/js/md5.min.js"></script>
    <!-- common.js -->
    <script type="text/javascript" src="/js/common.js"></script>
</head>
<body>
<div class="snow-container">
    <div class="snow foreground"></div>
    <div class="snow foreground layered"></div>
    <div class="snow middleground"></div>
    <div class="snow middleground layered"></div>
    <div class="snow background"></div>
    <div class="snow background layered"></div>
</div>

<div class="top-buttons-agileinfo">
    <a href="index.html">登录</a><a href="signup.html" class="active">注册</a>
</div>
<h1>Internship Sign In & Sign Up Form</h1>
<div class="main-agileits">
    <!--form-stars-here-->
    <div class="form-w3-agile">
        <h2 class="sub-agileits-w3layouts">注册</h2>
        <form name="registerForm" id="registerForm" method="post">
            <input id="mobile" name="mobile" placeholder="手机号码" type="text" required="true"
                   minlength="11" maxlength="11"/>
            <input id="password" name="password" type="password" placeholder="密码"
                   required="true" minlength="6" maxlength="16"/>
            <input id="repassword" name="repassword" type="password" placeholder="确认密码"
                   required="true" minlength="6" maxlength="16"/>
            <div class="submit-w3l">
                <input type="submit" onclick="register()" value="注 册">
            </div>
        </form>
    </div>
</div>
<script>
    function register() {
        $("#registerForm").validate({
            submitHandler: function (form) {
                doRegister();
            }
        });
    }

    function doRegister() {
        //加载中
        g_showLoading();

        var inputPass = $("#password").val();
        var repassword = $("#repassword").val();
        if (inputPass != repassword) {
            layer.msg("两次输入密码不一致！");
            return false;
        }
        var salt = g_passsword_salt;
        var str = "" + salt.charAt(0) + salt.charAt(2) + inputPass + salt.charAt(5) + salt.charAt(4);
        var password = md5(str);

        $.ajax({
            url: "/login/do_register",
            type: "POST",
            data: {
                mobile: $("#mobile").val(),
                password: password
            },
            success: function (data) {
                layer.closeAll();
                if (data.code == 0) {
                    layer.msg("成功");
                    window.location.href = "/goods/to_list";
                } else {
                    layer.msg(data.msg);
                }
            },
            error: function () {
                layer.closeAll();
            }
        });
    }
</script>
</body>
</html>
